home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue27 / tiptrix / listing1.pas next >
Encoding:
Pascal/Delphi Source File  |  1997-09-17  |  641 b   |  25 lines

  1. function TForm1.GetLastErrorText(dwError:DWORD):string;
  2. const
  3.  MAX_MSG_SIZE = 256;
  4. var
  5. szMsgBuf:array[0..MAX_MSG_SIZE-1] of char;
  6.  
  7.   function MakeLangID(p, s:DWORD):DWORD;
  8.   begin
  9.    result:= ((WORD(s) shl 10) or word(p));
  10.   end; {MakeLangID}
  11.  
  12. begin
  13.  if FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  14.                   nil,
  15.                   dwError,
  16.                   MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
  17.                   szMsgBuf,
  18.                   MAX_MSG_SIZE,
  19.                   nil)=0 then begin
  20.     result:=Format('Error %d',[dwError]);
  21.   end else begin
  22.     result:=szMsgBuf;
  23.   end;
  24. end; {GetLastErrorText}
  25.